package com.gonsin.gview.logic.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class TypeToken<T> {
    final Type type;

    protected TypeToken() {
        this.type = getSuperclassTypeParameter(this.getClass());
    }

    static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        } else {
            ParameterizedType parameterized = (ParameterizedType)superclass;
            return parameterized.getActualTypeArguments()[0];
        }
    }
}
